<?php

namespace app\store\controller\goods;

use app\store\controller\Controller;
use think\Db;
class Type extends Controller{

    public function index(){
        $list=Db::name('type')->select();
        return $this->fetch('',compact('list'));
    }


    public function delete($id) {
        $res=Db::name('type')->delete($id);
        if ($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }



    public function add(){

        if (request()->isPost()){
            $data=request()->param();
            $res=Db::name('type')->insert($data);
            if ($res){
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }

        return $this->fetch();
    }


    public function edit()  {
        $id=input('id');
        if (request()->isPost()){
            $data=request()->param();
            $res=Db::name('type')->where('id',$id)->update($data);
            if ($res){
                $this->success('更新成功');
            }else{
                $this->error('无数据更新');
            }
        }else{

            $model=Db::name('type')->find($id);
            return $this->fetch('',compact('model'));
        }
    }

}
